import ContextComponent from "../common/tool/context/ContextComponent";
import GameSnake from "./GameSnake";

const { ccclass, property } = cc._decorator;
@ccclass
export default class CameraContol extends ContextComponent {

    protected mGameSnake: GameSnake = null;
    public load(): void {
        this.mGameSnake = this.getContext(GameSnake);
    }

    public onUpdate(dt: number): void {
       
        let head = this.mGameSnake.SnakeHead;
        if (head) {
            var targetPos = head.convertToWorldSpaceAR(cc.Vec2.ZERO);
            var posy = this.node.parent.convertToNodeSpaceAR(targetPos).y;
            var step = ((posy + 100) - this.node.y) * 0.2;
            this.node.y += step;
        }
    }

}
